//
//  OwnViewController.m
//  iOS-CtrlV
//
//  Created by Wang Li on 12-12-19.
//  Copyright (c) 2012年 Wang Li. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
#import "OwnViewController.h"
#import "FansAndAttentionViewController.h"
#import "MainTabBarController.h"
#import "SettingViewController.h"
#import "MyHttpProcessor.h"
#import "AsyncImageView.h"
#import "AlbumModel.h"
#import "UserInformationModel.h"
#import "CollectListViewController.h"
#import "AlbumCell.h"
#import "LoginViewController.h"

#define MAXPALBUMAGENUM 20

@interface OwnViewController ()

@end

@implementation OwnViewController
@synthesize isPLook = m_isPLook;
- (id)init
{
    if (self = [super init]) {
        // Custom initialization
        type = 1002;
        m_albumdata = [[NSMutableArray alloc] init];
        m_type = MY_USER;
        isfans = YES;
        isalbum = YES;
        m_postnum = 0;
        m_goodnum = 0;
        m_albumnum = 0;
        isLook = YES;
        m_page = 1;
        isNextAndUp = 0;
        m_isPLook = YES;
m_tcellLsit = [[NSMutableArray alloc] init];
    }
    return self;
}
- (id)initUesrID:(NSString*)_UesrID
{
    if (self = [super init]) {
        // Custom initialization
        type = 1002;
        m_albumdata = [[NSMutableArray alloc] init];
        m_type = OTHER_USER;
        m_userid = _UesrID.integerValue;
        isfans = YES;
        isalbum = YES;
        m_postnum = 0;
        m_goodnum = 0;
        m_albumnum = 0;
        isLook = YES;
        m_page = 1;
        isNextAndUp = 0;
        m_isPLook = YES;
        m_tcellLsit = [[NSMutableArray alloc] init];

    }
    return self;
}
- (void)viewDidLoad
{
    [super viewDidLoad];

    
	// Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor colorWithRed:193/255.f green:193/255.f blue:193/255.f alpha:1]];
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
	// Do any additional setup after loading the view.
    if([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
        [self.navigationController.navigationBar setBackgroundImage:tAppDel.m_MidNavImg forBarMetrics: UIBarMetricsDefault];
        self.navigationController.navigationBar.clipsToBounds = NO;
        if ([self.navigationController.navigationBar viewWithTag:0x300] == nil) {
            UIImageView* tImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navshadow.png"]];
            tImgView.tag =0x300;
            tImgView.frame =CGRectMake(0, 44, 320, 5);
            [self.navigationController.navigationBar addSubview:tImgView];
            [tImgView release];
        }
    }
    
    if (m_type == MY_USER) {
        m_BackBttBarItem =[UIButton buttonWithType:UIButtonTypeCustom];
        m_BackBttBarItem.frame =CGRectMake(0, 0, 44, 44);
        [m_BackBttBarItem setImage:[UIImage imageNamed:@"setting.png"] forState:UIControlStateNormal];
        [m_BackBttBarItem addTarget:self action:@selector(ChangeSetting) forControlEvents:UIControlEventTouchUpInside];
        [m_BackBttBarItem retain];
    }else{
        m_BackBttBarItem =[UIButton buttonWithType:UIButtonTypeCustom];
        m_BackBttBarItem.frame =CGRectMake(0, 0, 44, 44);
        [m_BackBttBarItem setImage:[UIImage imageNamed:@"navback.png"] forState:UIControlStateNormal];
        [m_BackBttBarItem addTarget:self action:@selector(ChangeSetting) forControlEvents:UIControlEventTouchUpInside];
        [m_BackBttBarItem retain];
        
        m_settngBttBarItem =[UIButton buttonWithType:UIButtonTypeCustom];
        m_settngBttBarItem.frame =CGRectMake(self.navigationController.navigationBar.frame.size.width-44, 0, 44, 44);
        [m_settngBttBarItem setImage:[UIImage imageNamed:@"follow.png"] forState:UIControlStateNormal];
        [m_settngBttBarItem addTarget:self action:@selector(navSettingBtt) forControlEvents:UIControlEventTouchUpInside];
        [m_settngBttBarItem retain];
    }


    [self CreateHeadView];

    CGRect irect;
    if (m_type == MY_USER) {
        irect = CGRectMake(0, 128, 320, 480-44-128-49);
    }else{
        irect =CGRectMake(0, 128, 320, 480-44-128);
    }
    m_postTableView = [[UITableView alloc] initWithFrame:irect style:UITableViewStylePlain];
    [m_postTableView setBackgroundColor:[UIColor clearColor]];
    m_postTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    m_postTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//    [m_postTableView setBackgroundColor:[UIColor colorWithRed:180/250.f green:180/255.0f blue:180/255.0f alpha:1.0]];
    [m_postTableView setDataSource:self];
    [m_postTableView setDelegate:self];
    
    m_refreshHeaderView = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - m_postTableView.bounds.size.height, m_postTableView.bounds.size.width, m_postTableView.bounds.size.height)];
    m_refreshHeaderView.delegate = self;
    [m_postTableView addSubview:m_refreshHeaderView];
    [m_refreshHeaderView refreshLastUpdatedDate];
    


}
- (void)viewWillAppear:(BOOL)animated
{
       NSUserDefaults* tUserDef = [NSUserDefaults standardUserDefaults];
    MainTabBarController* tMainTabBar = (MainTabBarController*)self.navigationController.tabBarController;
    [self.view addSubview:tMainTabBar.m_TabbarCustom];

    if (m_type == MY_USER) {
        if ([m_BackBttBarItem superview] == nil) {
            [self.navigationController.navigationBar addSubview:m_BackBttBarItem];
        }
        tMainTabBar.m_TabbarCustom.hidden = NO;
    }else{
        NSInteger userid = [tUserDef stringForKey:@"user_id"].integerValue;
        if ([m_BackBttBarItem superview] == nil) {
            [self.navigationController.navigationBar addSubview:m_BackBttBarItem];
        }
        if ([m_settngBttBarItem superview] == nil && userid != m_userid) {
            [self.navigationController.navigationBar addSubview:m_settngBttBarItem];
        }
        tMainTabBar.m_TabbarCustom.hidden = YES;
    }

     type = 1002;
    if (type == 1003) {
        [m_postbutton setBackgroundColor:[UIColor whiteColor]];
        [m_albumbutton setBackgroundColor:[UIColor colorWithRed:236.0/255.0f green:238.0/255.0f blue:235.0/255.0f alpha:1.0f]];
        [m_goodbutton setBackgroundColor:[UIColor whiteColor]];
        [self.view addSubview:m_postTableView];
    }else if(type == 1002){
        [m_postbutton setBackgroundColor:[UIColor colorWithRed:236.0/255.0f green:238.0/255.0f blue:235.0/255.0f alpha:1.0f]];
        [m_goodbutton setBackgroundColor:[UIColor whiteColor]];
        [m_albumbutton setBackgroundColor:[UIColor whiteColor]];
    }else if(type == 1004)
    {
        [m_postbutton setBackgroundColor:[UIColor whiteColor]];
        [m_goodbutton setBackgroundColor:[UIColor colorWithRed:236.0/255.0f green:238.0/255.0f blue:235.0/255.0f alpha:1.0f]];
        [m_albumbutton setBackgroundColor:[UIColor whiteColor]];
    }
    if (m_type == MY_USER) {
        NSUserDefaults* tUserDef = [NSUserDefaults standardUserDefaults];
        m_userid = [tUserDef stringForKey:@"user_id"].integerValue;
//        UILabel* name = (UILabel*)[m_head viewWithTag:101];
//        name.text = [tUserDef stringForKey:@"nickname"];
//        AsyncImageView* asyimg = (AsyncImageView*)[m_head viewWithTag:100];
//        asyimg._imageRequestURL = [tUserDef stringForKey:@"avatar"];
//        asyimg.m_BoolSetImage = YES;
//        [asyimg customLoadImageFromURL];
    }
    if (m_isPLook) {
        if(iMyHttpProcessor == nil)
        {
            iMyHttpProcessor = [[MyHttpProcessor alloc] init];
            iMyHttpProcessor.delegate = self;
        }
        [iMyHttpProcessor RequestPersonalInformationGet:m_userid ID:m_userid];
//        [[MyHttpProcessor sharedManager] RequestPersonalInformationGet:m_userid ID:m_userid];
//        [MyHttpProcessor sharedManager].delegate = self;
        [self addHudLoad];
    }else{
        m_isPLook = YES;
    }


}
- (void)viewWillDisappear:(BOOL)animated
{
    if (m_type == MY_USER) {
        [m_BackBttBarItem removeFromSuperview];
    }else{
        [m_BackBttBarItem removeFromSuperview];
        [m_settngBttBarItem removeFromSuperview];
    }
    [tTieZiVC.view removeFromSuperview];
    [tLikeVC.view removeFromSuperview];
    [m_title removeFromSuperview];
    [m_postTableView removeFromSuperview];
}
- (void)CreateHeadView
{
    m_head = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 128)];
    m_head.backgroundColor = [UIColor colorWithRed:236.0/255.0f green:238.0/255.0f blue:235.0/255.0f alpha:1.0f];

    AsyncImageView* haed = [[AsyncImageView alloc] initWithFrame:CGRectMake(10, 8, 75, 75)];
    haed.tag = 100;
    [m_head addSubview:haed];
    [haed release];
    
    UILabel* name = [[UILabel alloc] initWithFrame:CGRectMake(99, 22, self.view.frame.size.width-130, 20)];
    name.tag = 101;
    name.backgroundColor = [UIColor clearColor];
    name.font = [UIFont boldSystemFontOfSize:18.0f];
    name.textColor = [UIColor colorWithRed:51/255.0f green:51/255.0f blue:51/255.0f alpha:1.0f];
    name.text = @" ";
    [m_head addSubview:name];
    [name release];
    
   

    UIButton* guan = [UIButton buttonWithType:UIButtonTypeCustom];
    guan.frame = CGRectMake(98, 48, 66, 35);
    [guan setBackgroundImage:[UIImage imageNamed:@"button01.png"] forState:UIControlStateNormal];
    guan.tag = 1000;
    [guan setTitleColor:[UIColor colorWithRed:121.0/255.0f green:121.0/255.0f blue:121.0/255.0f alpha:1.0f] forState:UIControlStateNormal];
    [guan setTitle:@"0 粉丝" forState:UIControlStateNormal];
     guan.titleLabel.font = [UIFont systemFontOfSize:13.0f];
    [guan addTarget:self action:@selector(ChangeButton:) forControlEvents:UIControlEventTouchUpInside];
    [m_head addSubview:guan];
    
    UIButton* feng = [UIButton buttonWithType:UIButtonTypeCustom];
    feng.frame = CGRectMake(98+66,48,66,35);
    [feng setBackgroundImage:[UIImage imageNamed:@"button02.png"] forState:UIControlStateNormal];
    feng.tag = 1001;
    [feng setTitleColor:[UIColor colorWithRed:121.0/255.0f green:121.0/255.0f blue:121.0/255.0f alpha:1.0f]forState:UIControlStateNormal];
    [feng setTitle:@"0 关注" forState:UIControlStateNormal];
     feng.titleLabel.font = [UIFont systemFontOfSize:13.0f];
    [feng addTarget:self action:@selector(ChangeButton:) forControlEvents:UIControlEventTouchUpInside];
    [m_head addSubview:feng];
    

    
  
    NSInteger w = self.view.frame.size.width/3;
    m_postbutton = [UIButton buttonWithType:UIButtonTypeCustom];
    m_postbutton.layer.borderColor = [UIColor colorWithRed:193.0/255.0f green:193.0/255.0f blue:193.0/255.0f alpha:1.0f].CGColor;
    m_postbutton.layer.borderWidth = 1.0f;
    m_postbutton.frame = CGRectMake(0, 128-35,w , 35);
    m_postbutton.tag = 1002;
    [m_postbutton setTitleColor:[UIColor colorWithRed:121.0/255.0f green:121.0/255.0f blue:121.0/255.0f alpha:1.0f] forState:UIControlStateNormal];
    [m_postbutton setTitle:@"0 帖子" forState:UIControlStateNormal];
    m_postbutton.titleLabel.font = [UIFont systemFontOfSize:13.0f];
    [m_postbutton addTarget:self action:@selector(ChangeButton:) forControlEvents:UIControlEventTouchUpInside];
    [m_head addSubview:m_postbutton];
    
    m_albumbutton = [UIButton buttonWithType:UIButtonTypeCustom];
    m_albumbutton.layer.borderColor = [UIColor colorWithRed:193.0/255.0f green:193.0/255.0f blue:193.0/255.0f alpha:1.0f].CGColor;;
    m_albumbutton.layer.borderWidth = 1.0f;
    m_albumbutton.frame = CGRectMake(w-1,  128-35,w+2 , 35);
    m_albumbutton.tag = 1003;
    [m_albumbutton setTitleColor:[UIColor colorWithRed:121.0/255.0f green:121.0/255.0f blue:121.0/255.0f alpha:1.0f] forState:UIControlStateNormal];
    [m_albumbutton setTitle:@"0 专辑" forState:UIControlStateNormal];
    m_albumbutton.titleLabel.font = [UIFont systemFontOfSize:13.0f];
    [m_albumbutton addTarget:self action:@selector(ChangeButton:) forControlEvents:UIControlEventTouchUpInside];
    [m_head addSubview:m_albumbutton];
    
    m_goodbutton = [UIButton buttonWithType:UIButtonTypeCustom];
    m_goodbutton.layer.borderColor = [UIColor colorWithRed:193.0/255.0f green:193.0/255.0f blue:193.0/255.0f alpha:1.0f].CGColor;;
    m_goodbutton.layer.borderWidth = 1.0f;
    m_goodbutton.tag = 1004;
    m_goodbutton.frame = CGRectMake(w*2,  128-35, w+2, 35);
    m_goodbutton.titleLabel.textColor = [UIColor blackColor];
    [m_goodbutton setTitleColor:[UIColor colorWithRed:121.0/255.0f green:121.0/255.0f blue:121.0/255.0f alpha:1.0f] forState:UIControlStateNormal];
    [m_goodbutton setTitle:@"0 喜欢" forState:UIControlStateNormal];
      m_goodbutton.titleLabel.font = [UIFont systemFontOfSize:13.0f];
    [m_goodbutton addTarget:self action:@selector(ChangeButton:) forControlEvents:UIControlEventTouchUpInside];
    [m_head addSubview:m_goodbutton];
    
    UIImageView* tImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navshadow.png"]];
    tImgView.frame =CGRectMake(0, 128, 320, 5);
    [m_head addSubview:tImgView];
        [tImgView release];
    [self.view addSubview:m_head];
}

- (void)CreatetitelView:(NSString*)str rect:(CGRect)_rect
{
    if (m_title != nil) {
        [m_title release];
        m_title = nil;
    }
    m_title = [[UIView alloc] initWithFrame:_rect];
    [m_title setBackgroundColor:[UIColor clearColor]];
    CGSize iSize  = [str sizeWithFont:[UIFont systemFontOfSize:24.0f]];
    NSInteger x = (m_title.frame.size.width-iSize.width)/2;
    NSInteger y = (m_title.frame.size.height-iSize.height)/2;
    UILabel* name = [[UILabel alloc] initWithFrame:CGRectMake(x, y,iSize.width, iSize.height)];
    name.tag = 101;
    name.backgroundColor = [UIColor clearColor];
    name.font = [UIFont boldSystemFontOfSize:24.f];
    name.textColor = [UIColor colorWithRed:128.0/255.0f green:128.0/255.0f blue:128.0/255.0f alpha:1.0f];
    name.shadowColor = [UIColor colorWithRed:230/255.0f green:230/255.0f blue:230/255.0f alpha:1.0f];
    name.shadowOffset = CGSizeMake(0, 1);
    name.text = str;
//    name.numberOfLines = 0;
    [m_title addSubview:name];
    [name release];
    [self.view addSubview:m_title];
    [self.view sendSubviewToBack:m_title];
}
//切换界面和状态
- (void)ChangeButton:(UIButton*)ibutton
{
    switch (ibutton.tag) {
        case 1000://粉丝
        {
            if (isfans) {
                
                FansAndAttentionViewController* ifansandattent = [[FansAndAttentionViewController alloc] initType:FANSTYPE];
                MainTabBarController* tMainTabBar = (MainTabBarController*)self.navigationController.tabBarController;
                ifansandattent.user_id = [tMainTabBar.m_UserDic objectForKey:@"user_id"];
                ifansandattent.m_TargetID = [NSString stringWithFormat:@"%d",m_userid];
                ifansandattent.navigationItem.hidesBackButton =YES;
                ifansandattent.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:ifansandattent animated:YES];
                [ifansandattent release];
          
            }else{
                
            }

            break;
        }
        case 1001://关注
        {
            if (isalbum) {
                FansAndAttentionViewController* ifansandattent = [[FansAndAttentionViewController alloc] initType:ATTENTYP];
                MainTabBarController* tMainTabBar = (MainTabBarController*)self.navigationController.tabBarController;
                ifansandattent.user_id = [tMainTabBar.m_UserDic objectForKey:@"user_id"];
                ifansandattent.m_TargetID = [NSString stringWithFormat:@"%d",m_userid];
                ifansandattent.navigationItem.hidesBackButton =YES;
                ifansandattent.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:ifansandattent animated:YES];
                [ifansandattent release];
            }else{
                
            }

            break;
        }
        case 1002://帖子
        {
            type = 1002;
            [m_postbutton setBackgroundColor:[UIColor colorWithRed:236.0/255.0f green:238.0/255.0f blue:235.0/255.0f alpha:1.0f]];
            [m_goodbutton setBackgroundColor:[UIColor whiteColor]];
            [m_albumbutton setBackgroundColor:[UIColor whiteColor]];
            [m_postTableView removeFromSuperview];
            [tLikeVC.view removeFromSuperview];
            if (m_title.superview != nil) {
                [m_title removeFromSuperview];
            }
            if (m_postnum != 0) {
                if (tTieZiVC == nil) {
                    tTieZiVC = [[PBLViewController alloc] init];
                    
                    tTieZiVC.m_RquestURL = [NSString stringWithFormat:@"%@?app=userNew&act=blogs&user_id=%d&id=%d",RequestMainURL,m_userid,m_userid];
                    tTieZiVC.m_SuperNavVC = self.navigationController;
                    if (m_type == MY_USER) {
                        tTieZiVC.m_NowModeType =Mode_Type_ShortInfoShow;
                    }else{
                        tTieZiVC.m_NowModeType =Mode_Type_InfoShow;
                    }
                    [tTieZiVC firstDataGet];
                }
                [self.view addSubview:tTieZiVC.view];
                [self.view sendSubviewToBack:tTieZiVC.view];

            }else{
                [m_title removeFromSuperview];
                CGRect irect;
                if (m_type == MY_USER) {
                    irect = CGRectMake(0, 128, 320, 480-44-128-60);
                }else{
                    irect =CGRectMake(0, 128, 320, 480-44-128);
                }

                [self CreatetitelView:@"暂无帖子" rect:irect];
            }
            break;
        }
        case 1003://专辑
        {
            type = 1003;
            [m_postbutton setBackgroundColor:[UIColor whiteColor]];
            [m_goodbutton setBackgroundColor:[UIColor whiteColor]];
            [m_albumbutton setBackgroundColor:[UIColor colorWithRed:236.0/255.0f green:238.0/255.0f blue:235.0/255.0f alpha:1.0f]];
            [tTieZiVC.view removeFromSuperview];
            [tLikeVC.view removeFromSuperview];
            if (m_title.superview != nil) {
                [m_title removeFromSuperview];
            }
            NSLog(@"h1 ==== %f",m_postTableView.frame.size.height);
            if (m_albumnum != 0) {
                if ([m_postTableView superview] == nil) {
                    CGRect irect;
                    if (m_type == MY_USER) {
                        irect = CGRectMake(0, 128, 320, 480-44-128-60);
                    }else{
                        irect =CGRectMake(0, 128, 320, 480-44-128);
                    }
                    [self.view addSubview:m_postTableView];
                    [self.view sendSubviewToBack:m_postTableView];
                    

                }
                [self requestPageData];
                [self addHudLoad];
            }else{
                [m_title removeFromSuperview];
                CGRect irect;
                if (m_type == MY_USER) {
                    irect = CGRectMake(0, 128, 320, 480-44-128-60);
                }else{
                    irect =CGRectMake(0, 128, 320, 480-44-128);
                }

                  [self CreatetitelView:@"暂无专辑" rect:irect];

            }

            break;
        }
    
        case 1004://喜好
        {
            type = 1004;
            [m_postbutton setBackgroundColor:[UIColor whiteColor]];
            [m_goodbutton setBackgroundColor:[UIColor colorWithRed:236.0/255.0f green:238.0/255.0f blue:235.0/255.0f alpha:1.0f]];
            [m_albumbutton setBackgroundColor:[UIColor whiteColor]];
            [m_postTableView removeFromSuperview];
            [tTieZiVC.view removeFromSuperview];
            [m_title removeFromSuperview];
            if (m_title.superview != nil) {
                [m_title removeFromSuperview];
            }
            if (m_goodnum!= 0) {
                if (tLikeVC == nil) {
                    tLikeVC = [[PBLViewController alloc] init];
                    tLikeVC.m_SuperNavVC = self.navigationController;
                    if (m_type == MY_USER) {
                        tLikeVC.m_NowModeType =Mode_Type_ShortInfoShow;
                    }else{
                        tLikeVC.m_NowModeType =Mode_Type_InfoShow;
                    }
                    
                    MainTabBarController* tMainTabBar =(MainTabBarController*)self.navigationController.tabBarController;
                    if (tMainTabBar.m_UserDic == nil) {
                        tLikeVC.m_RquestURL = [NSString stringWithFormat:@"%@?app=userNew&act=likes&user_id=%d&id=%d",RequestMainURL,0,m_userid];
                    }else{
                        NSUserDefaults* tUserDef = [NSUserDefaults standardUserDefaults];
                        tLikeVC.m_RquestURL = [NSString stringWithFormat:@"%@?app=userNew&act=likes&user_id=%d&id=%d",RequestMainURL,[tUserDef stringForKey:@"user_id"].intValue,m_userid];
                    }

                    [tLikeVC firstDataGet];
                    
                }
                [self.view addSubview:tLikeVC.view];
                [self.view sendSubviewToBack:tLikeVC.view];
            }else{
                [m_title removeFromSuperview];
                CGRect irect;
                if (m_type == MY_USER) {
                    irect = CGRectMake(0, 128, 320, 480-44-128-60);
                }else{
                    irect =CGRectMake(0, 128, 320, 480-44-128);
                }

             [self CreatetitelView:@"暂无喜欢" rect:irect];
            }

            break;
        }
    }
}
- (void)ChangeSetting
{
    if (m_type == MY_USER) {
        SettingViewController* setting = [[SettingViewController alloc] init];
        setting.delegate = self;
        setting.headimage =[((AsyncImageView*)[m_head viewWithTag:100]) GetUIImage];
        UILabel* nlabel = (UILabel*)[m_head viewWithTag:101];
        setting.name = nlabel.text;
        setting.navigationItem.hidesBackButton =YES;
        MainTabBarController* tMainTabBar = (MainTabBarController*)self.navigationController.tabBarController;
        tMainTabBar.m_TabbarCustom.hidden = YES;
        [self.navigationController pushViewController:setting animated:YES];
        [setting release];
    }
    else
    {
        MainTabBarController* tMainTabBar = (MainTabBarController*)self.navigationController.tabBarController;
        tMainTabBar.m_TabbarCustom.hidden = NO;
        [self.navigationController popViewControllerAnimated:YES];
    }

}
- (void)navSettingBtt
{
    MainTabBarController* tMainTabBar =(MainTabBarController*)self.navigationController.tabBarController;
    if (tMainTabBar.m_UserDic == nil) {
        LoginViewController* tLoginVC =[[LoginViewController alloc] init];
        UINavigationController* tNav =[tMainTabBar.viewControllers objectAtIndex:tMainTabBar.selectedIndex];
        tLoginVC.navigationItem.hidesBackButton =YES;
        tNav.hidesBottomBarWhenPushed =YES;
        [tNav pushViewController:tLoginVC animated:YES];
        [tLoginVC release];
    }else{
        NSUserDefaults* tUserDef = [NSUserDefaults standardUserDefaults];
        NSString* userid = (NSString*)[tUserDef stringForKey:@"user_id"];
        [iMyHttpProcessor RequestFollowGet:userid targe:[NSString stringWithFormat:@"%d",m_userid] type:1];
        [self addHudLoad];
    }

}
- (void)popview
{
    MainTabBarController* tMainTabBar = (MainTabBarController*)self.navigationController.tabBarController;
    tMainTabBar.m_TabbarCustom.hidden = NO;
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)requestPageData
{
    if (isLook) {
        isLook = NO;
//      [[MyHttpProcessor sharedManager] RequestAlbumListGet:m_userid ID:[NSNumber numberWithInt:m_userid].stringValue start:m_page limit:MAXPALBUMAGENUM];
        [iMyHttpProcessor RequestAlbumListGet:m_userid ID:[NSNumber numberWithInt:m_userid].stringValue start:m_page limit:MAXPALBUMAGENUM];
    }
}
#pragma mark -
#pragma mark SettingViewDelegate
- (void)ModifyNameText:(NSString*)text
{
    if (text.length > 0) {
        UILabel* name = (UILabel*)[m_head viewWithTag:101];
        [name setText:text];
    }
}
- (void)ModifyHaedText:(UIImage*)text
{
    if (text!= nil) {
        AsyncImageView* asyimg = (AsyncImageView*)[m_head viewWithTag:100];
        [asyimg SetUIImage:text];
    }
}
- (void)CreateCell
{
    static NSString* tSStrCell = @"FansAndAttentioncell";
    NSUInteger row  = 0;
    NSInteger num1 = [m_albumdata count]%2;
    
    if (num1 == 0) {
        row = [m_albumdata count]/2;
    }else{
        row = [m_albumdata count]/2+1;
    }
    NSInteger maxnum = [m_albumdata count];
    for (int j = 0; j < row; j++) {
        AlbumCell* tCell = [[AlbumCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tSStrCell];
        [tCell setBackgroundColor:[UIColor clearColor]];
        tCell.selectionStyle = UITableViewCellSelectionStyleNone;
        tCell.delegate = self;
        for (int i = 0; i < 2; ++i) {
            NSInteger a = i+j*2;
            if (a == maxnum) {
                [tCell.albumView2 removeFromSuperview];
                break;
            }
            AlbumModel* amodel = [m_albumdata objectAtIndex:a];
            NSString* jie = [NSString stringWithFormat:@"%@%d",amodel.albumtitle,amodel.count];
            if (i == 0) {
                [tCell.albumView1 setData:amodel.userheadimgurls name:jie];
                tCell.albumView1.tag  = a;
            }
            else
            {
                [tCell.albumView2 setData:amodel.userheadimgurls name:jie];
                tCell.albumView2.tag  = a;
            }
        }
        [m_tcellLsit addObject:tCell];
    }
 
}
#pragma mark -
#pragma mark UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 200;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
#pragma mark UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSUInteger num  = 0;
    NSLog(@"%d",[m_albumdata count]);
    NSInteger num1 = [m_albumdata count]%2;

    if (num1 == 0) {
          num = [m_albumdata count]/2;
    }else{
          num = [m_albumdata count]/2+1;
    }
    return num;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
 
    return (UITableViewCell*)[m_tcellLsit objectAtIndex:indexPath.row];
}
#pragma mark AlbumCellDelegate
- (void)getAlbumTag:(NSInteger)_tag
{
    NSLog(@"tag%d",_tag);
    AlbumModel* tAlbDic= [m_albumdata objectAtIndex:_tag];
    MainTabBarController* tMainTabBar = (MainTabBarController*)self.navigationController.tabBarController;
    tMainTabBar.m_TabbarCustom.hidden =YES;
    CollectListViewController* tNextVC = [[CollectListViewController alloc] init];
    tNextVC.navigationItem.hidesBackButton =YES;
    tNextVC.m_NowModeType=Mode_Type_CollectList;
    tNextVC.m_UserID =[NSString stringWithFormat:@"%d",tAlbDic.userid];
//    tNextVC.m_ShowUserID = [NSString stringWithFormat:@"%d",tAlbDic.userid];
    tNextVC.m_Collect_ID = tAlbDic.albumid;
    tNextVC.type = m_type;
    [self.navigationController pushViewController:tNextVC animated:YES];
    [tNextVC release];
}
#pragma mark SettingViewDelegate
- (void)Cleanup
{
    
    [tTieZiVC release];
    tTieZiVC = nil;
   [tLikeVC release];
    tLikeVC = nil;
}
#pragma mark MyHttpProcessorDelegate
//个人信息
- (void)OutPersonalInformationData:(UserInformationModel*)_data
{
    [self hudWasHidden:nil];
//    NSInteger userid = _data.user_id;
//    if (m_type == MY_USER) {
//        
//    }else{
        UILabel* name = (UILabel*)[m_head viewWithTag:101];
        name.text = _data.uesr_name;
        AsyncImageView* asyimg = (AsyncImageView*)[m_head viewWithTag:100];
        asyimg._imageRequestURL = _data.user_headimg_url;
        asyimg.m_BoolSetImage = YES;
        [asyimg customLoadImageFromURL];
//    }

    
    UIButton* fans =(UIButton*)[m_head viewWithTag:1000];
    NSString* fanss = _data.user_fans_count;
    NSString* str = [NSString stringWithFormat:@"%@ 粉丝",fanss];
    [fans setTitle:str forState:UIControlStateNormal];
    
    
    UIButton* guan =(UIButton*)[m_head viewWithTag:1001];
    NSString* follows = _data.uesr_follow_count;
    NSString* str1 = [NSString stringWithFormat:@"%@ 关注",follows];
    [guan setTitle:str1 forState:UIControlStateNormal];
    
    m_postnum = _data.user_blog_count;
    NSString* post = [NSString stringWithFormat:@"%d 帖子",m_postnum];
    [m_postbutton setTitle:post forState:UIControlStateNormal];
    
    m_albumnum = _data.user_collect_count;
    NSString* album = [NSString stringWithFormat:@"%d 专辑",m_albumnum];
    [m_albumbutton setTitle:album forState:UIControlStateNormal];
    
    m_goodnum = _data.user_like_count;
    NSString* good = [NSString stringWithFormat:@"%d 喜欢",m_goodnum];
    [m_goodbutton setTitle:good forState:UIControlStateNormal];

    switch (type) {
        case 1002://帖子
            if (m_postnum != 0) {
                if (tTieZiVC == nil) {
                    tTieZiVC = [[PBLViewController alloc] init];
                    
                    MainTabBarController* tMainTabBar =(MainTabBarController*)self.navigationController.tabBarController;
                    if (tMainTabBar.m_UserDic == nil) {
                        tTieZiVC.m_RquestURL = [NSString stringWithFormat:@"%@?app=userNew&act=blogs&user_id=%d&id=%d",RequestMainURL,0,m_userid];
                    }else{
                        NSUserDefaults* tUserDef = [NSUserDefaults standardUserDefaults];
                        tTieZiVC.m_RquestURL = [NSString stringWithFormat:@"%@?app=userNew&act=blogs&user_id=%d&id=%d",RequestMainURL,[tUserDef stringForKey:@"user_id"].intValue,m_userid];
                    }

                    tTieZiVC.m_SuperNavVC = self.navigationController;
                    if (m_type == MY_USER) {
                        tTieZiVC.m_NowModeType = Mode_Type_ShortInfoShow;
                    }else{
                        tTieZiVC.m_NowModeType = Mode_Type_InfoShow;
                    }
                    [tTieZiVC firstDataGet];
                }
                [self.view addSubview:tTieZiVC.view];
                [self.view sendSubviewToBack:tTieZiVC.view];
            }else{
                CGRect irect;
                if (m_type == MY_USER) {
                    irect = CGRectMake(0, 128, 320, 480-20-44-128-49);
                }else{
                    irect =CGRectMake(0, 128, 320, 480-20-44-128);
                }
               [self CreatetitelView:@"暂无帖子" rect:irect];
            }
   
            break;
        case 1003://专题
            if (m_albumnum != 0) {
//                [[MyHttpProcessor sharedManager] RequestAlbumListGet:m_userid ID:[NSNumber numberWithInt:m_userid].stringValue start:0 limit:1];
                [iMyHttpProcessor RequestAlbumListGet:m_userid ID:[NSNumber numberWithInt:m_userid].stringValue start:0 limit:21];
                [self addHudLoad];
            }else{
                CGRect irect;
                if (m_type == MY_USER) {
                    irect = CGRectMake(0, 155, 320, 480-20-44-150-49);
                }else{
                    irect =CGRectMake(0, 155, 320, 480-20-44-150);
                }
                [self CreatetitelView:@"暂无专辑" rect:irect];
            }
            break;
        case 1004://喜好
            if (m_goodnum != 0) {
                if (tLikeVC == nil) {
                    tLikeVC = [[PBLViewController alloc] init];
                    tLikeVC.m_SuperNavVC = self.navigationController;
                    if (m_type == MY_USER) {
                        tLikeVC.m_NowModeType =Mode_Type_ShortInfoShow;
                    }else{
                        tLikeVC.m_NowModeType =Mode_Type_InfoShow;
                    }
                    
                    MainTabBarController* tMainTabBar =(MainTabBarController*)self.navigationController.tabBarController;
                    if (tMainTabBar.m_UserDic == nil) {
                        tLikeVC.m_RquestURL = [NSString stringWithFormat:@"%@?app=userNew&act=likes&user_id=%d&id=%d",RequestMainURL,0,m_userid];
                    }else{
                        NSUserDefaults* tUserDef = [NSUserDefaults standardUserDefaults];
                        tLikeVC.m_RquestURL = [NSString stringWithFormat:@"%@?app=userNew&act=likes&user_id=%d&id=%d",RequestMainURL,[tUserDef stringForKey:@"user_id"].intValue,m_userid];
                    }

                    [tLikeVC firstDataGet];
                    
                }
                [self.view addSubview:tLikeVC.view];
                [self.view sendSubviewToBack:tLikeVC.view];
            }else{
                CGRect irect;
                if (m_type == MY_USER) {
                    irect = CGRectMake(0, 155, 320, 480-20-44-150-49);
                }else{
                    irect =CGRectMake(0, 155, 320, 480-20-44-150);
                }
                [self CreatetitelView:@"暂无喜欢" rect:irect];
            }

            break;
    }
    

}
//帖子
- (void)OutPostListData:(NSMutableArray*)_data
{
    
}
//专题
- (void)OutAlbumListData:(NSMutableArray*)_data
{

    [self hudWasHidden:nil];
    [self doneLoadingTableViewData];
    
     NSInteger num = [_data count];

    if (num > 0) {
        if ([m_albumdata count]> 0) {
            [m_albumdata removeAllObjects];
        }
        if ([m_tcellLsit count]> 0) {
            [m_tcellLsit removeAllObjects];
        }
        for (int i = 0; i < [_data count]; ++i) {
            [m_albumdata addObject:[_data objectAtIndex:i]];
        }
        [self CreateCell];
        CGPoint offset = m_postTableView.contentOffset;
        offset.y = 0;
        m_postTableView.contentOffset = offset;
        [m_postTableView reloadData];
    }else{
        
        if ([m_albumdata count]> 0) {
            if (isNextAndUp == 1) {//下一页
                if(m_page>1)m_page--;
                NSLog(@"m_page = %d",m_page);
            }
            else if(isNextAndUp == 2)//上一页
            {
                 m_page++;
            }
            
        }else{
            CGRect irect;
            if (m_type == MY_USER) {
                irect = CGRectMake(0, 155, 320, 480-20-44-150-49);
            }else{
                irect =CGRectMake(0, 155, 320, 480-20-44-150);
            }
            
            [self CreatetitelView:@"暂无专题" rect:irect];
        }

    }
    isNextAndUp = 0;
    isLook = YES;
}
//喜好
- (void)OutGoodListData:(NSMutableArray*)_data
{
    
}
//异常
- (void)OurErrer:(NSDictionary *)dic
{
    AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
    [tAppDel showWithCustomView:@"提示" detailText:[dic objectForKey:@"errorMsg"] isCue:YES delayTime:3.0f];
    [self hudWasHidden:nil];
    [self doneLoadingTableViewData];
    isLook = YES;

    if (isNextAndUp == 1) {//下一页
        if(m_page>1)m_page--;
    }
    else if(isNextAndUp == 2)//上一页
    {
        m_page++;
    }
    isNextAndUp = 0;
}

- (void)OutFollow:(NSString *)_data
{
    [self hudWasHidden:nil];
    if (_data == nil) {
        AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
        [tAppDel showWithCustomView:@"提示" detailText:@"网络异常" isCue:NO delayTime:2.0f];
        return;
    }
    if (_data.integerValue == 1) {
        AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
        [tAppDel showWithCustomView:@"提示" detailText:@"添加关注成功" isCue:NO delayTime:2.0f];
    }else{
        AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
        [tAppDel showWithCustomView:@"提示" detailText:@"添加关注失败" isCue:NO delayTime:2.0f];
    }
}
#pragma mark -
#pragma mark MBProgressHUDDelegate
- (void)hudWasHidden:(MBProgressHUD *)hud{
    m_MBHUD.delegate = nil;
	[m_MBHUD removeFromSuperview];
	[m_MBHUD release];
	
	m_MBHUD=nil;
}

-(void) addHudLoad{
	if (m_MBHUD == nil) {
		m_MBHUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
		// Add HUD to screen
		[self.navigationController.view addSubview:m_MBHUD];
		// Regisete for HUD callbacks so we can remove it from the window at the right time
		m_MBHUD.delegate = self;
		m_MBHUD.labelText = @"请求数据中...";
		[m_MBHUD show:YES];
	}
}


#pragma mark -
#pragma mark UIScrollViewDelegate Methods
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    int tShowH =0;
    if ([scrollView isEqual:m_postTableView]) {
        [m_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
        tShowH = scrollView.contentOffset.y+scrollView.frame.size.height;
        if (tShowH > scrollView.contentSize.height+60&&isLook) {
            m_page++;
            [self requestPageData];
            isNextAndUp = 1;
        }
    }
    
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
	
	[m_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
}

#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate Methods

- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
	
	[self reloadTableViewDataSource];
    if (m_page > 1) {
        m_page--;
        [self requestPageData];
        isNextAndUp = 2;
    }else{
        AppDelegate* tAppDel = (AppDelegate*)[UIApplication sharedApplication].delegate;
        [tAppDel showWithCustomView:@"提示" detailText:@"已经是第一页" isCue:NO delayTime:2.0f];
        [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:1.0f];
    }
}

- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
	
	return m_reloading; // should return if data source model is reloading
	
}

- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{
	
	return [NSDate date]; // should return date data source was last changed
}

#pragma mark -
#pragma mark Data Source Loading / Reloading Methods

- (void)reloadTableViewDataSource{
	
	//  should be calling your tableviews data source model to reload
	//  put here just for demo
	m_reloading = YES;
	
}

- (void)doneLoadingTableViewData{
	
	//  model should call this when its done loading
	m_reloading = NO;
	[m_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:m_postTableView];
	
}

-(void)dealloc
{
    [m_head release];
    [m_postTableView release];
    m_postbutton = nil;
    m_goodbutton = nil;
    m_albumbutton = nil;
    [tTieZiVC release];
    [tLikeVC release];
    m_BackBttBarItem = nil;
    [m_title release];
     [self hudWasHidden:nil];
    [iMyHttpProcessor release];
    m_refreshHeaderView.delegate = nil;
    [m_refreshHeaderView release];
    [m_tcellLsit removeAllObjects];
    [m_tcellLsit release];
    [super dealloc];
}
@end
